import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { TableColumn } from '@/types/table'
import { fileUplodeUrl,templateTypeOpt,createTimeTypeOpt,imgSizeOpt,userInfo } from '../indexData'

// 表单校验
export const rules = reactive({
  address: [{ required: true, message: '服务器不能为空', trigger: 'blur' }],
  port: [{ required: true, message: '端口不能为空', trigger: 'blur' }],
  codedFormat: [{ required: true, message: '编码不能为空', trigger: 'blur' }],
  mode: [{ required: true, message: '请选择模式', trigger: 'change' }],
  list: [{ required: true,message: '不能为空', }],
  templateType: [{ required: true,message: '不能为空', }],
  templateName: [{ required: true,message: '不能为空', }],
  sort: [{ required: true,message: '不能为空', }],
  imgSize: [{ required: true,message: '不能为空', }],
  fileType: [{ required: true,message: '不能为空', }],
  topicType: [{ required: true,message: '不能为空', }],
  pictureName: [{ required: true,message: '不能为空', }],
  deptName: [{ required: true,message: '不能为空', }],
  createTimeType: [{ required: true,message: '不能为空', }],
  createDeptName: [{ required: true, message: '不能为空',}],
  createUserName: [{ required: true, message: '不能为空',}],
})
export const modeOpt=[
  {
    value:'0',label:'重要信息'
  },
  {
    value:'1',label:'灾情报告'
  },
  {
    value:'2',label:'图件图表'
  },
  {
    value:'3',label:'救援行动'
  }
]
const produceTypeOpt=[
  {
    value:'0',label:'否'
  },
  {
    value:'1',label:'是'
  },
]
// CrudSchema：https://doc.iocoder.cn/vue3/crud-schema/
const crudSchemas = reactive<CrudSchema[]>([
  // {
  //   field: 'selection',
  //   type: 'selection',
  //   isdetail: false,
  //   isForm:false
  // },
  {
    label: '模版',
    field: 'list',
    isTable:false,
    isDetail:false,
    form:{
      component: 'UploadFile',
      value:[],
      componentProps: {
        limit: 1,
        action: fileUplodeUrl,
        fileList: [],
        multiple: false,
      }
    }
  },
  {
    label: '模板类型',
    field: 'templateType',
    isSearch: false,
    isTable:false,
    isDetail:false,
    form:{
      component: 'Select',
      componentProps: {
          options: templateTypeOpt
      },
      
    }
  },
  {
    label: '模版名称',
    field: 'templateName',
    minWidth: 250,
    search: {
      show: true,
      component: 'Input',
    },
    form: {
      componentProps: {
        maxlength:'40',
      }
    }
  },
  {
    label: '产出顺序',
    field: 'sort',
    isSearch: false,
    isForm:false,
    isDetail:false,
  },
  {
    label: '幅面',
    field: 'imgSize',
    isDetail: false,
    isForm: false,
    isTable: false,
    form:{
      component: 'Select',
      componentProps: {
          options: imgSizeOpt
      }
    },
    search: {
      show: true,
      component: 'Select',
      componentProps: {
        options: imgSizeOpt,
        optionsAlias: {
          labelField: 'label',
          valueField: 'label'
        }
      }
    },
  },
  {
    label: '模板类型',
    field: 'templateType',
    search: {
      show: true,
      component: 'Select',
      // api: () => templateTypeOpt,
      componentProps: {
        options: templateTypeOpt,
        optionsAlias: {
          labelField: 'label',
          valueField: 'label'
        }
      }
    },
    isForm:false
  },
  {
    label: '是否产出',
    field: 'produceType',
    isDetail: false,
    isForm: false,
    isTable: false,
    search: {
      show: true,
      component: 'Select',
      componentProps: {
        options: produceTypeOpt,
        optionsAlias: {
          labelField: 'label',
          valueField: 'value'
        }
      }
    },
  },
  {
    label: '产出顺序',
    field: 'sort',
    isSearch: false,
    isTable:false,
  },
  {
    label: '幅面',
    field: 'imgSize',
    isSearch: false,
    isDetail:false,
    form:{
      component: 'Select',
      componentProps: {
          options: imgSizeOpt
      }
    },
  },
  {
    label: '模板类型',
    field: 'templateType',
    search:{
      component: 'Select',
      componentProps: {
          options: templateTypeOpt
      }
    },
    isForm:false,
    isTable:false
  },
  {
    label: '产出',
    field: 'produceType',
    isForm:false,
    isDetail:false
  },
  {
    label: '共享',
    field: 'isShare',
    isForm:false,
    isDetail:false
  },
  
  {
    label: '专题类型',
    field: 'topicType',
    isSearch: false,
    isTable:false,
    dictType: DICT_TYPE.TOPICTYPE,
    form:{
      component: 'Select',
      // componentProps: {
      //     options: modeOpt
      // }
    },
  },
  {
    label: '文件类型',
    field: 'fileType',
    isSearch: false,
    isTable:false,
    form:{
      component: 'Select',
      componentProps: {
          options: modeOpt
      }
    },
  },
  {
    label: '图件名称',
    field: 'pictureName',
    isSearch: false,
    isTable:false,

  },
  {
    label: '制图单位',
    field: 'deptName',
    isTable:false,
    form:{
      value:userInfo.dept.name,
    }
  },
  {
    label: '制图日期',
    field: 'createTimeType',
    isTable:false,
    formatter: (_: Recordable, __: TableColumn, cellValue: number|string) => {
      return createTimeTypeOpt.find((account) => account.value === cellValue)?.label
    },
    form: {
        component: 'Select',
        componentProps: {
            options: createTimeTypeOpt
        }
    }
  },
  {
    label: '是否自动打印',
    field: 'printType',
    isTable:false,
    isForm:false,
  },
  {
    label: '是否共享',
    field: 'isShare',
    isTable:false,
    isForm:false,
  },
  {
    label: '是否产出',
    field: 'produceType',
    isTable:false,
    isForm:false,
  },
  {
    label: ' ',
    field: 'printType',
    isTable:false,
    isDetail:false,

    form: {
      colProps:{
        span:4
      },
        component: 'Checkbox',
        componentProps: {
            options: [
                {
                  label: '自动打印',
                }
            ]
        }
    }
  },
  {
    label: ' ',
    field: 'isShare',
    isTable:false,
    isDetail:false,
    form: {
      colProps:{
        span:4
      },
        component: 'Checkbox',
        componentProps: {
            options: [
                {
                  label: '共享',
                }
            ]
        }
    }
  },
  {
    label: ' ',
    field: 'produceType',
    isTable:false,
    isDetail:false,
    form: {
        colProps:{
          span:6
        },
        component: 'Checkbox',
        componentProps: {
            options: [
                {
                  label: '产出',
                }
            ]
        }
    }
  },
  {
    field: 'createUserName',
    label:'维护人',
    with:'',
    form:{
      colProps:{
        span:12
      },
      value:userInfo.nickname,
    }
  },
  {
    field: 'createDeptName',
    label:'维护人所属单位',
    table:{
      width:128
    },
    form:{
      value:userInfo.dept.name,
    }
  },
  
  {
    field: 'createUserId',
    label:'维护人',
    isTable:false,
    isForm:false,
    isDetail:false,
    form:{
      value:userInfo.id,
    }
  },
  {
    field: 'createDeptId',
    label:'维护人所属单位',
    isTable:false,
    isForm:false,
    isDetail:false,
    form:{
      value:userInfo.deptId,
    }
  },
  {
    label: '操作',
    field: 'action',
    isDetail: false,
    isForm:false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
